return nitems;
}
+/* This function has been copied straight from the x11 backend */
+static gchar *
+sanitize_utf8 (const gchar *src,
+ gboolean return_latin1)
+{
+ gint len = strlen (src);
+ GString *result = g_string_sized_new (len);
+ const gchar *p = src;
+
+ while (*p)
+ {
+ if (*p == '\r')
+ {
+ p++;
+ if (*p == '\n')
+ p++;
+
+ g_string_append_c (result, '\n');
+ }
+ else
+ {
+ gunichar ch = g_utf8_get_char (p);
+
+ if (!((ch < 0x20 && ch != '\t' && ch != '\n') || (ch >= 0x7f && ch < 0xa0)))
+ {
+ if (return_latin1)
+ {
+ if (ch <= 0xff)
+ g_string_append_c (result, ch);
+ else
+ g_string_append_printf (result,
+ ch < 0x10000 ? "\\u%04x" : "\\U%08x",
+ ch);
+ }
+ else
+ {
+ char buf[7];
+ gint buflen;
+
+ buflen = g_unichar_to_utf8 (ch, buf);
+ g_string_append_len (result, buf, buflen);
+ }
+ }
+
+ p = g_utf8_next_char (p);
+ }
+ }
+
+ return g_string_free (result, FALSE);
+}
+
gchar *
_gdk_wayland_display_utf8_to_string_target (GdkDisplay *display,
const gchar *str)
{
- return NULL;
+ /* This is mainly needed when interfacing with old clients through
+ * Xwayland, the STRING target could be used, and passed as-is
+ * by the compositor.
+ *
+ * There's already some handling of this atom (aka "mimetype" in
+ * this backend) in common code, so we end up in this vfunc.
+ */
+ return sanitize_utf8 (str, TRUE);
}
void